//
//  ZMyOrderManagerAddressCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/15.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZMyOrderManagerAddressCell.h"

@interface ZMyOrderManagerAddressCell ()
@property (nonatomic, strong) UILabel *lblDate;//日期
@property (nonatomic, strong) UILabel *lblName;//收货人姓名
@property (nonatomic, strong) UILabel *lblPhone;//收货人手机号
@property (nonatomic, strong) UILabel *lblAddress;//收货人地址
@end

@implementation ZMyOrderManagerAddressCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupViewAction];
    }
    return self;
}

#pragma mark - 界面布局
- (void)setupViewAction{
    _lblDate = [[UILabel alloc] initWithFrame:CGRectMake(16, 11, kScreen_Width - 32, 17)];
    _lblDate.font = [UIFont systemFontOfSize:12];
    _lblDate.textColor = kColorWithHex(0x999999);
    [self.contentView addSubview:_lblDate];
    
    UILabel *lblNoticeName = [[UILabel alloc] initWithFrame:CGRectMake(16, 40, 65, 20)];
    lblNoticeName.text = @"收 货 人:";
    lblNoticeName.font = [UIFont systemFontOfSize:14];
    lblNoticeName.textColor = kColorWithHex(0x333333);
    [self.contentView addSubview:lblNoticeName];
    
    UILabel *lblNoticeAddress = [[UILabel alloc] initWithFrame:CGRectMake(16, 65, 65, 20)];
    lblNoticeAddress.text = @"收货地址:";
    lblNoticeAddress.font = [UIFont systemFontOfSize:14];
    lblNoticeAddress.textColor = kColorWithHex(0x333333);
    [self.contentView addSubview:lblNoticeAddress];
    
    _lblName = [UILabel new];
    _lblName.font = [UIFont boldSystemFontOfSize:14];
    _lblName.textColor = kColorWithHex(0x272727);
    [self.contentView addSubview:_lblName];
    [_lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblNoticeName.mas_top);
        make.leading.equalTo(lblNoticeName.mas_trailing).offset(10);
        make.height.mas_equalTo(20);
    }];
    
    _lblPhone = [UILabel new];
    _lblPhone.font = [UIFont boldSystemFontOfSize:14];
    _lblPhone.textColor = kColorWithHex(0x272727);
    [self.contentView addSubview:_lblPhone];
    [_lblPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblNoticeName.mas_top);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-16);
        make.height.mas_equalTo(20);
    }];
    
    UIImageView *ivPhone = [UIImageView new];
    ivPhone.image = imgname(@"phone_green_icon");
    [self.contentView addSubview:ivPhone];
    [ivPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lblPhone.mas_centerY);
        make.trailing.equalTo(self.lblPhone.mas_leading).offset(-9);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    UIButton *btnPhone = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnPhone addTarget:self action:@selector(btnPhoneClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:btnPhone];
    [btnPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lblPhone.mas_centerY);
        make.height.mas_equalTo(20);
        make.leading.equalTo(ivPhone.mas_leading);
        make.trailing.equalTo(self.lblPhone.mas_trailing);
    }];
    
    _lblAddress = [UILabel new];
    _lblAddress.font = [UIFont boldSystemFontOfSize:12];
    _lblAddress.textColor = kColorWithHex(0x272727);
    _lblAddress.numberOfLines = 2;
    _lblAddress.preferredMaxLayoutWidth = kScreen_Width - 102;
    [self.contentView addSubview:_lblAddress];
    [_lblAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblName.mas_leading);
        make.trailing.equalTo(self.lblPhone.mas_trailing);
        make.top.equalTo(lblNoticeName.mas_bottom).offset(8);
    }];
    
    UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 116, kScreen_Width, 2)];
    viewLine.backgroundColor = kColorWithHex(0xf2f2f2);
    [self.contentView addSubview:viewLine];
}
#pragma mark - 数据更新
- (void)setOrderModel:(ZOrderManagerListModel *)orderModel{
    if (orderModel) {
        _orderModel = orderModel;
        _lblDate.text = orderModel.createTime;
        _lblName.text = orderModel.name;
        _lblPhone.text = orderModel.phone;
        _lblAddress.text = orderModel.address;
    }
}
#pragma mark - 交互事件
- (void)btnPhoneClickAction:(UIButton *)sender{
    if (_orderModel) {
        [HFTools callMobilePhone:_orderModel.phone];
    }
}
+ (CGFloat)cellHeight{
    return 118.0;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
